/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model.report;

import entities.ReportDetails;
import java.util.ArrayList;
import java.util.Date;
import javax.swing.event.TableModelListener;
import javax.swing.table.TableModel;

/**
 *
 * @author VietLH
 */
public class ReportViewAllTblMdl implements TableModel {

    private ArrayList<ReportDetails> reportList;
    private String[] header = {"Patient Name", "Test Name", "Test Date", "Staff Name", "Doctor Name", "Status"};

    public ReportViewAllTblMdl(ArrayList<ReportDetails> reportList) {
        this.reportList = new ArrayList<ReportDetails>();
        this.reportList = reportList;
    }

    public void setHeader(String[] header) {
        this.header = header;
    }

    @Override
    public int getRowCount() {
        if (this.reportList != null) {
            return this.reportList.size();
        } else {
            return 0;
        }
    }

    @Override
    public int getColumnCount() {
        return header.length;
    }

    @Override
    public String getColumnName(int columnIndex) {
        return header[columnIndex];
    }

    @Override
    public Class<?> getColumnClass(int columnIndex) {
        if (columnIndex == 2) {
            return Date.class;
        }
        return String.class;
    }

    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        return false;
//        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        if (reportList.size() > 0 && reportList != null) {
            if (columnIndex == 0) {
                //return (reportList.get(rowIndex).getPatientDetails().getpID()+" - "+reportList.get(rowIndex).getPatientDetails().getpFName() + " " + reportList.get(rowIndex).getPatientDetails().getpLName());
                return (reportList.get(rowIndex));
            } else if (columnIndex == 1) {
                return (reportList.get(rowIndex).getTest().getTestName());
            } else if (columnIndex == 2) {
                return (reportList.get(rowIndex).getTestDate());
            } else if (columnIndex == 3) {
                if (reportList.get(rowIndex).getStaffDetail().getStaffFName() != null && reportList.get(rowIndex).getStaffDetail().getStaffLName() != null) {
                    return (reportList.get(rowIndex).getStaffDetail().getStaffFName() + " " + reportList.get(rowIndex).getStaffDetail().getStaffLName());
                } else {
                    return "-----";
                }
            } else if (columnIndex == 4) {
                if (reportList.get(rowIndex).getDoctorDetails().getdFName() != null && reportList.get(rowIndex).getDoctorDetails().getdLName() != null) {
                    return (reportList.get(rowIndex).getDoctorDetails().getdFName() + " " + reportList.get(rowIndex).getDoctorDetails().getdLName());
                } else {
                    return "-----";
                }
            } else if (columnIndex == 5) {
                if (reportList.get(rowIndex).getStatus() < 0) {
                    return "Not Start!";
                } else if (reportList.get(rowIndex).getStatus() == 0) {
                    return "In Progress!";
                } else {
                    return "Finished!";
                }
            } else {
                return null;
            }
        }
        return "--";
//        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
//        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void addTableModelListener(TableModelListener l) {
//        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void removeTableModelListener(TableModelListener l) {
//        throw new UnsupportedOperationException("Not supported yet.");
    }
}
